package de.virtualpet;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Actions 
{
//	private static int maxpropertyvalue = 100;
	
	public static void LetPetPropertysFall(Pet virtualpet)
	{
		//the interval in witch the hunger rises.
		 int hungerInterval = 2;
		//the interval in witch the tiredness rises.
		 int tirednessInterval = 1;
		//the interval in witch the happiness falls.
		 int happinessInterval = 2;
		//the interval in witch the hygiene falls.
		 int hygieneInterval = 1;
		 
		 if((virtualpet.Gethunger() - hungerInterval) > 0)
			{
			 	virtualpet.Sethunger(virtualpet.Gethunger() - hungerInterval);
			}
			else 
			{
				virtualpet.Sethunger(virtualpet.Gethunger() - (100 - virtualpet.Gethunger()));
			}
		 
		 if((virtualpet.Gettiredness() - tirednessInterval) > 0)
			{
			 virtualpet.Settiredness(virtualpet.Gettiredness() - tirednessInterval);
			}
			else 
			{
				virtualpet.Settiredness(virtualpet.Gettiredness() - (100 - virtualpet.Gettiredness()));
			}
		 
		 if((virtualpet.Gethappiness() - happinessInterval) > 0)
			{
			 virtualpet.Sethappiness(virtualpet.Gethappiness() - happinessInterval);
			}
			else 
			{
				virtualpet.Sethappiness(virtualpet.Gethappiness() - (100 - virtualpet.Gethappiness()));
			}
		 
		 if((virtualpet.Gethygiene() - hygieneInterval) > 0)
			{
			 virtualpet.Sethygiene(virtualpet.Gethygiene() - hygieneInterval);
			}
			else 
			{
				virtualpet.Sethygiene(virtualpet.Gethygiene() - (100 - virtualpet.Gethappiness()));
			}
		
		
		
	}
	
	public static String GetUnsuficentPropertys(Pet virtualpet)
	{
		int properatyValueToCompare = 50;
		String lowestProperty = "";
		
		Map<String, Object> propertys = new HashMap<String, Object>();
		propertys.put("happiness", virtualpet.Gethappiness());
		propertys.put("hunger",virtualpet.Gethunger());
		propertys.put("hygiene",virtualpet.Gethygiene());
		propertys.put("tiredness",virtualpet.Gettiredness());
		
		Set<String> keys = propertys.keySet();
	    
		for (String singleKey : keys) 
		{
			if((Integer)propertys.get(singleKey) < properatyValueToCompare)
			{
				properatyValueToCompare = (Integer)propertys.get(singleKey);
				lowestProperty = singleKey;
			}
		}
		return lowestProperty;
	}
	
	public static void Eat(Pet virtualpet)
	{
		if((virtualpet.Gethunger() + 20) < 10)
		{
			virtualpet.Sethunger(virtualpet.Gethunger() + 20);
		}
		else 
		{
			virtualpet.Sethunger(virtualpet.Gethunger() + (100 - virtualpet.Gethunger()));
		}
	}
	
	public static void Wash(Pet virtualpet)
	{
		if((virtualpet.Gethygiene() + 60) < 100)
		{
			virtualpet.Sethygiene(virtualpet.Gethygiene() + 60);
		}
		else 
		{
			virtualpet.Sethygiene(virtualpet.Gethygiene() + (100 - virtualpet.Gethygiene()));
		}
	}
	
	public static boolean Sleep(Pet virtualpet)
	{
		boolean isfull = false;
		if((virtualpet.Gettiredness() + 15) < 100)
		{
			virtualpet.Settiredness(virtualpet.Gettiredness() + 15);
		}
		else 
		{
			virtualpet.Sethygiene(virtualpet.Gettiredness() + (100 - virtualpet.Gettiredness()));
			isfull = true;
		}
		return isfull;
	}
	
	public static void Play(Pet virtualpet)
	{
		if((virtualpet.Gethappiness() + 30) < 100)
		{
			virtualpet.Sethappiness(virtualpet.Gethappiness() + 30);
		}
		else 
		{
			virtualpet.Sethappiness(virtualpet.Gethappiness() + (100 - virtualpet.Gethappiness()));
		}
	}
}
